{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import keras\n",
    "from keras import models\n",
    "from keras import layers\n",
    "from keras.preprocessing.text import Tokenizer\n",
    "from keras.preprocessing.sequence import pad_sequences\n",
    "import os\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "imdb_bir = \"F:\\\\workspace\\\\kaggle\\\\datasets\\\\aclImdb\\\\aclImdb\\\\train\\\\\"\n",
    "glove_dir = \"F:\\\\workspace\\\\kaggle\\\\datasets\\\\glove.6B\\\\\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "['glove.6B.100d.txt', 'glove.6B.200d.txt', 'glove.6B.300d.txt', 'glove.6B.50d.txt']\n"
     ]
    }
   ],
   "source": [
    "print(len(os.listdir(imdb_bir)))\n",
    "print(os.listdir(glove_dir))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "#读取评论\n",
    "labels = []\n",
    "texts = []\n",
    "\n",
    "for label in ['neg','pos']:\n",
    "    dir_name = os.path.join(imdb_bir,label)\n",
    "    for fname in os.listdir(dir_name):\n",
    "        if fname[-4:] == \".txt\":\n",
    "            f =open(os.path.join(dir_name,fname),encoding=\"utf-8\")\n",
    "            texts.append(f.read())\n",
    "            if label == 'neg':\n",
    "                labels.append(0)\n",
    "            if label == 'pos':\n",
    "                labels.append(1)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "#分词\n",
    "maxlen = 100\n",
    "max_words = 10000\n",
    "tokenizer = Tokenizer(num_words=max_words)\n",
    "tokenizer.fit_on_texts(texts)\n",
    "sequence = tokenizer.texts_to_sequences(texts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "88582\n"
     ]
    }
   ],
   "source": [
    "word_index = tokenizer.word_index\n",
    "print(len(word_index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pad_sequences(sequence,maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape of data tensor: (25000, 100)\n",
      "Shape of label tensor: (25000,)\n"
     ]
    }
   ],
   "source": [
    "labels = np.asarray(labels)\n",
    "print('Shape of data tensor:', data.shape)\n",
    "print('Shape of label tensor:', labels.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "#构建训练数据和测试数据\n",
    "indices = np.arange(data.shape[0])\n",
    "np.random.shuffle(indices)\n",
    "data = data[indices]\n",
    "labels = labels[indices]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train_samples = 10000\n",
    "val_samples = 1000\n",
    "x_train = data[:train_samples]\n",
    "y_train = labels[:train_samples]\n",
    "x_val = data[train_samples:train_samples+val_samples]\n",
    "y_val = labels[train_samples:train_samples+val_samples]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "#对嵌入数据预处理\n",
    "embeddings_index = {}\n",
    "f = open(os.path.join(glove_dir,\"glove.6B.100d.txt\"),encoding='utf-8')\n",
    "for line in f:\n",
    "    values = line.split()\n",
    "    word = values[0]\n",
    "    ceof = np.asarray(values[1:],dtype='float32')\n",
    "    embeddings_index[word] = ceof\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#将GloVe词嵌入矩阵\n",
    "embeddings_dim = 100\n",
    "\n",
    "embeddings_mat = np.zeros((max_words,embeddings_dim))\n",
    "for word,i in word_index.items():\n",
    "    if i < max_words:\n",
    "        embedding_v = embeddings_index.get(word)\n",
    "        if embedding_v is not None:\n",
    "            embeddings_mat[i] = embedding_v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_8 (Embedding)      (None, 100, 100)          1000000   \n",
      "_________________________________________________________________\n",
      "lstm_3 (LSTM)                (None, 32)                17024     \n",
      "_________________________________________________________________\n",
      "dense_13 (Dense)             (None, 64)                2112      \n",
      "_________________________________________________________________\n",
      "dense_14 (Dense)             (None, 1)                 65        \n",
      "=================================================================\n",
      "Total params: 1,019,201\n",
      "Trainable params: 1,019,201\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "#定义模型\n",
    "model = models.Sequential()\n",
    "model.add(layers.Embedding(max_words,embeddings_dim,input_length=maxlen))\n",
    "model.add(layers.LSTM(32))\n",
    "model.add(layers.Dense(64,activation='relu'))\n",
    "model.add(layers.Dense(1,activation='sigmoid'))\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_8 (Embedding)      (None, 100, 100)          1000000   \n",
      "_________________________________________________________________\n",
      "lstm_3 (LSTM)                (None, 32)                17024     \n",
      "_________________________________________________________________\n",
      "dense_13 (Dense)             (None, 64)                2112      \n",
      "_________________________________________________________________\n",
      "dense_14 (Dense)             (None, 1)                 65        \n",
      "=================================================================\n",
      "Total params: 1,019,201\n",
      "Trainable params: 19,201\n",
      "Non-trainable params: 1,000,000\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "#设置嵌入层 weights\n",
    "model.layers[0].set_weights([embeddings_mat])\n",
    "model.layers[0].trainable = False\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model.compile(optimizer=keras.optimizers.RMSprop(),loss=keras.losses.binary_crossentropy,metrics=['acc'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 10000 samples, validate on 1000 samples\n",
      "Epoch 1/10\n",
      "10000/10000 [==============================] - 13s 1ms/step - loss: 0.6580 - acc: 0.6086 - val_loss: 0.6632 - val_acc: 0.6160\n",
      "Epoch 2/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.5888 - acc: 0.6950 - val_loss: 0.5476 - val_acc: 0.7250\n",
      "Epoch 3/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.5533 - acc: 0.7184 - val_loss: 0.5419 - val_acc: 0.7240\n",
      "Epoch 4/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.5269 - acc: 0.7354 - val_loss: 0.6265 - val_acc: 0.6690\n",
      "Epoch 5/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.5026 - acc: 0.7590 - val_loss: 0.4920 - val_acc: 0.7700\n",
      "Epoch 6/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.4794 - acc: 0.7718 - val_loss: 0.7630 - val_acc: 0.6480\n",
      "Epoch 7/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.4521 - acc: 0.7865 - val_loss: 0.8453 - val_acc: 0.6550\n",
      "Epoch 8/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.4371 - acc: 0.7979 - val_loss: 0.6851 - val_acc: 0.6560\n",
      "Epoch 9/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.4243 - acc: 0.8031 - val_loss: 0.4445 - val_acc: 0.7850\n",
      "Epoch 10/10\n",
      "10000/10000 [==============================] - 12s 1ms/step - loss: 0.4062 - acc: 0.8143 - val_loss: 0.4380 - val_acc: 0.7740\n"
     ]
    }
   ],
   "source": [
    "hist = model.fit(x_train,y_train,batch_size=128,epochs=10,validation_data=(x_val,y_val))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmUVPWZ//H3A4ItLhFZEmVrjBgRZW1R4ooIQiVBXEHb\njL9MIpmZaHRi3GNkNMw4OePEzLhEzEzi0aZx6VYxIjQqYBxRAZcYEAVRoYFos4vs9Pf3x7eKrt6r\nu+vWvVX1eZ3T53bdunXvQ2nXU/e7PF9zziEiItKUdmEHICIi0adkISIizVKyEBGRZilZiIhIs5Qs\nRESkWUoWIiLSLCULERFplpKFiIg0S8lCRESadVDYAaRL165dXWFhYdhhiIhklSVLlmxwznVr7ric\nSRaFhYUsXrw47DBERLKKmX2WynFqhhIRkWYpWYiISLOULEREpFk502fRkL1791JZWcmuXbvCDiXr\nFBQU0LNnTzp06BB2KCISATmdLCorKzn88MMpLCzEzMIOJ2s459i4cSOVlZX07ds37HBEJAJyuhlq\n165ddOnSRYmihcyMLl266I5MJOJKSqCwENq189uSkuCuldN3FoASRSvpfROJtpISmDwZduzwjz/7\nzD8GKC5O//Vy+s5CRCRX3X57TaJI2LHD7w+CkkWAtmzZwoMPPtiq18ZiMbZs2ZLmiEQkV6xe3bL9\nbaVkkSTd7X9NJYv9+/c3+dpZs2Zx5JFHti0AEclZvXu3bH9bKVnEJdr/PvsMnKt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PtzrnDwo5DJEhqhhIRkWbpzkJERJqlOwsREWmWkoWI\niDRLyUJERJqlZCEiIs1SshARkWYpWYiISLP+P83XMeXEUmPlAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x24fa602c748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "epcho = range(1,len(hist.history['acc'])+1)\n",
    "plt.plot(epcho,hist.history['acc'],'bo',label=\"train acc\")\n",
    "plt.plot(epcho,hist.history['val_acc'],'b',label=\"val acc\")\n",
    "plt.xlabel(\"epcho\")\n",
    "plt.ylabel('acc')\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??layers.LSTM()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
